<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
    <div id="app">
        <!-- 过滤器常用来处理文本格式化的操作。过滤器可以用在两个地方：双花括号插值和v-bind表达式 -->
        <li v-for="user in userList">
            {{user.id}}==>{{user.name}}==>{{user.gender}}
            ==>{{user.gender==1?"男":"女"}}
            ==>{{user.gender | genderFilter}}
            ==>{{user.gender | gfFilter}}
        </li>

    </div>
    <script>
        //定义全局过滤器
        Vue.filter("gfFilter", function (val) {
            if (val == 1) {
                return "男";
            }
            return "女";
        });
        let vm = new Vue({
            el: "#app",
            data: {
                userList: [
                    { id: 1, name: 'jack', gender: 1 },
                    { id: 2, name: 'peter', gender: 0 }
                ]
            },
            filters: {
                //具部过滤器，只可以在当前vue实例中使用
                genderFilter(val) {
                    if (val == 1) {
                        return "男";
                    }
                    return "女";
                }
            }
        });
    </script>
</body>

</html>